var articleType = "";
var title = "";

$(function () {
    var bodyW = $(window).width();
    var bodyH = $(window).height();
    $(".part_1").height(bodyH);

    function addclass(e) {
        var win_h = $(window).height() * 1.4;
        var t = $(e).offset().top;
        var top = $(window).scrollTop();
        if (top > t - win_h) {
            $(e).addClass("on")
        }
    };$(window).scroll(function () {
        var top = $(document).scrollTop();
        if (top > 150) {
            $(".navbar-fixed-top").css({"background-Color": "#000", "transition": "background-Color ease-in-out 0.6s",})
        } else if (top < 150) {
            $(".navbar-fixed-top").css({
                "background-Color": "transparent",
                "transition": "background-Color ease-in-out 0.6s",
            })
        }
        ;addclass(".part_2 .major");
        addclass(".part_2 .div_p");
        addclass(".part_2 .div_url");
        addclass(".part_3 .major");
        addclass(".part_3 .row");
        addclass(".part_4 .major");
        addclass(".part_4 .row");
        addclass(".part_4 .div_url")
    })
})
$(function(){
    //根据不同浏览设备，加载不同图片
    pic_html();
    function pic_html(){
        if($(window).width()>1024){
            $(".part_1").attr("class","index_img part_1");
        }else{
            $(".part_1").attr("class","index_img2 part_1");
        }
    }
    //当调整浏览器窗口的大小时，发生 resize 事件
    $(window).resize(function(){
        pic_html();
    })


    articlelist();
    linklist();

    function articlelist(){
        $.ajax({
            type:"get",
            url:"/api/article",
            data:{
                pageSize: 3,
                articleType:articleType,
                pageNumber:0,
                title:title
            },
            async:true,
            dataType:"json",
            success:function(data){

                var data = data.data;
                if(data!=undefined&&data!=null){
                    var str = "";
                    for(var i=0;i<data.length;i++){
                        str += "<div class=\"col-sm-4 col-md-4 row_div\">"+
                        "<a href=\"/context/"+data[i].id+"\">"+
                        "<div class=\"thumbnail\">"+
                        "<img src='"+data[i].cover+"'>"+
                            "<span>"+data[i].title+"</span>"+
                        "</div></a>"+
                        "</div>"
                    }

                    $("#articlelist").append(str);
                }
            },
            error:function(err){
                // layer.msg("服务繁忙，请稍后再试！",{icon: 1});
            }
        });
    }

    function linklist(){
        $.ajax({
            url: "/api/link",
            type: "get",
            dataType: "json",
            data:{
                "pageSize":7,
                "pageNumber":0
            },
            success: function (result) {
                if (result.code==200){
                    var data = result.data;
                    var str="";
                    for(var i=0;i<data.length;i++){
                        str += "<div class=\"col-xs-6 col-sm-3 col-md-2 row_div\">"+
                        "<div class=\"thumbnail\">"+
                        "<a href='"+data[i].url+"'>"+
                            "<p>"+
                            "<img class=\"part_link\" src='"+data[i].icon+"'>"+
                            "</p>"+
                            "<p style=\"color: #000;font-size: 14px;display: none;\">"+data[i].username+"</p>"+
                        "</a>"+
                        "</div>"+
                        "</div>";
                    }
                    $("#linklist").append(str);
                }
            },
            error: function (err) {
                // layer.msg("服务繁忙，请稍后再试！",{icon: 1});
            },
            complete: function () {
            }
        });

    }



})

